package org.sanmao.wyj.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.*;
import org.sanmao.wyj.domain.User;


import java.util.List;

@Mapper
public interface UserDao extends BaseMapper<User> {


    @Select("select * from user where uid = #{id}")
    User getById(int id);

    @Delete("delete from user where uid = #{id}")
    int deleteById(int id);

    @Select("select * from user where username = #{username} and password = #{password}")
    User findUserByUsernameAndPassword(@Param("username")String username, @Param("password") String password);

    @Select("select * from user where name like CONCAT('%', #{name} ,'%')")
    IPage<User> findUserByName(IPage<User>page,@Param("name") String name);

    @Select("select * from user where username = #{username} and phonenum = #{phonenum}")
    User finUserByUsernameAndPhonenum(@Param("username")String username, @Param("phonenum")String phonenum);

    @Select("select * from user where username = #{username}")
    User findUserOnlyByUsername(String username);

    @Select("select u.*,count(o.uid) as order_count from user as u left join orders as o on u.uid = o.uid where u.uid = #{id}")
    User findMe(int id);

}
